import type { LocaleSetting, LocaleType } from '@/locales'
import { LOCALE, localeSetting } from '@/locales'
import { defineStore } from 'pinia'

const lsLocaleSetting = localeSetting as LocaleSetting

interface LocaleState {
    localeInfo: LocaleSetting
}

export const useLocaleStore = defineStore({
    id: 'locale',
    state: (): LocaleState => ({
        localeInfo: lsLocaleSetting
    }),
    getters: {
        getLocale(): LocaleType {
            return this.localeInfo?.locale ?? LOCALE.EN_US
        }
    },
    actions: {
        setLocaleInfo(info: Partial<LocaleSetting>) {
            this.localeInfo = {
                ...this.localeInfo,
                ...info
            }
        }
    }
})
